package com.shenmazong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shenmazong.entity.TbArticle;
import com.shenmazong.entity.TbOutline;
import com.shenmazong.entity.TbStage;
import com.shenmazong.mapper.StageMapper;
import com.shenmazong.mapper.TbArticleMapper;
import com.shenmazong.mapper.TbOutlineMapper;
import com.shenmazong.service.TbOutlineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.ListParamVo;
import com.shenmazong.vo.OutLineVo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 大纲表 ——> John
 服务实现类
 * </p>
 *
 * @author 还怕大雨吗
 * @since 2021-09-18
 */
@Service
public class TbOutlineServiceImpl extends ServiceImpl<TbOutlineMapper, TbOutline> implements TbOutlineService {

    @Resource
    private TbOutlineMapper tbOutlineMapper;

    @Resource
    private StageMapper stageMapper;

    @Resource
    private TbArticleMapper tbArticleMapper;


    /***
     * @description 查询阶段包含的所有大纲
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 15:42
     */
    @Override
    @Cacheable(value = "selectTBOutline")
    public ResultResponse selectTBOutline(ListParamVo listParamVo) {
        IPage<OutLineVo> page = tbOutlineMapper.selectOutLinePage(
                new Page<OutLineVo>(listParamVo.getCurrent(),listParamVo.getSize()),
                 listParamVo.getParamMap().get("stageID")
        );
        System.out.println("page = " + page.getRecords());
        return ResultResponse.SUCCESS(page);
    }

    /***
     * @description 对阶段新增某一个大纲
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 15:46
     */
    @Override
    @CacheEvict(value = "selectTBOutline",allEntries = true)
    public ResultResponse insertTbOutLine(TbOutline listParamVo) {
        tbOutlineMapper.insert( listParamVo);
        return ResultResponse.SUCCESS();
    }

    /***
     * @description 对大纲名称进行修改
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 15:47
     */
    @Override
    @CacheEvict(value = "selectTBOutline",allEntries = true)
    public ResultResponse updateTboutLine(TbOutline listParamVo) {
        tbOutlineMapper.updateById(listParamVo);
        return ResultResponse.SUCCESS();
    }

    /***
     * @description 删除某一个大纲
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 15:47
     */
    @Override
    @CacheEvict(value = "selectTBOutline",allEntries = true)
    public ResultResponse deleteTboutLine(Long listParamVo) {
        tbOutlineMapper.deleteById(listParamVo);
        return ResultResponse.SUCCESS();
    }

    /***
     * @description 查询全部阶段
     * @params [stageNo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/23 13:38
     */
    @Override
    public ResultResponse selectStage(Long stageNo) {
        List<TbStage> tbStages = stageMapper.selectList(
                new QueryWrapper<TbStage>().lambda().eq(TbStage::getMajorId, stageNo)
        );
        return ResultResponse.SUCCESS(tbStages);
    }


    /***
     * @description 查询单个文章详情信息
     * @params [article]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/26 8:49
     */
    @Override
    public ResultResponse selectOutline(Long article) {
        TbArticle tbArticle = tbArticleMapper.selectById(article);
        return ResultResponse.SUCCESS(tbArticle);
    }


}
